﻿using SheXiangTou.Beans;
using SheXiangTou.Services;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace SheXiangTou.Controller
{
    public class MachineControl
    {
        public void Deployment()
        {
            if (!CHCNetSDK.NET_DVR_Init()) { Console.WriteLine("SDK初始化失败！"); return; } //初始化SDK

            #region 设置报警回调函数
            MacService.m_falarmData_V31 = MacService.Event_Callback;
            CHCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(MacService.m_falarmData_V31, IntPtr.Zero);
            CHCNetSDK.NET_DVR_SETUPALARM_PARAM struAlarmParam = new CHCNetSDK.NET_DVR_SETUPALARM_PARAM();
            struAlarmParam.dwSize = (uint)Marshal.SizeOf(struAlarmParam);
            struAlarmParam.byLevel = 1; //0- 一级布防,1- 二级布防
            struAlarmParam.byAlarmInfoType = 1;//智能交通设备有效，新报警信息类型
            struAlarmParam.byFaceAlarmDetection = 1;//1-人脸侦测
            struAlarmParam.byDeployType = 0;//只能写客户端布防 否则无法触发远程校验事件
            #endregion
            MacService.Login_Id = MacService.LoginDevice(ConfigerService.Device_Ip, ConfigerService.Device_Port, ConfigerService.Device_Account, ConfigerService.Device_Pwd);
            if (MacService.Login_Id == -1)
            {
                Console.WriteLine("登录设备失败,错误码:" + CHCNetSDK.NET_DVR_GetLastError());
            }
            else
            {
                if (CHCNetSDK.NET_DVR_SetupAlarmChan_V41(MacService.Login_Id, ref struAlarmParam) < 0)//设置报警通道
                {
                    Console.WriteLine("布防失败，设置报警通道失败，错误码:" + CHCNetSDK.NET_DVR_GetLastError());
                }
                else
                {
                    Console.WriteLine(DateTime.Now + "------------->摄像头布防成功!!!");
                }
            }
        }

        public void AddUser(UserCardMQ userCardMQ)
        {
            new MacService().AddUser(userCardMQ);
        }
        public void RemoveUser(UserCardMQ userCardMQ)
        {
            new MacService().RemovePeopleFace(userCardMQ);
        }
    }
}
